package com.gec.hawaste.mapper;

import com.gec.hawaste.entity.SysResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gec.hawaste.entity.SysRoleDo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author gec
 * @since 2022-11-23
 */
public interface SysResourceMapper extends BaseMapper<SysResource> {
    @Select("select sre.* " +
            "from sys_role sr, " +
            "sys_role_resource srr, " +
            "sys_resource sre " +
            "where " +
            "srr.role_id = #{id} " +
            "and sr.del_flag=0 " +
            "and srr.del_flag=0 " +
            "and sre.del_flag=0 " +
            "and sr.id = srr.role_id " +
            "and srr.resource_id = sre.id;")
    List<SysResource> selectByRid(Long id);

    @Select("   SELECT DISTINCT \n" +
            "\t  sre.*  \n" +
            "    FROM  \n" +
            "\t sys_user sus,  \n" +
            "\t sys_user_role sur,  \n" +
            "\t sys_role sro,  \n" +
            "\t sys_role_resource srr,  \n" +
            "\t sys_resource sre   \n" +
            "    WHERE  \n" +
            "\tsus.id = #{uid}  \n" +
            "\tAND sus.del_flag=0  \n" +
            "\tAND sur.del_flag=0  \n" +
            "\tAND sro.del_flag = 0   \n" +
            "\tAND srr.del_flag=0  \n" +
            "\tAND sre.del_flag = 0   \n" +
            "\tAND sus.id=sur.user_id  \n" +
            "\tAND sur.role_id = sro.id   \n" +
            "\tAND sro.id = srr.role_id   \n" +
            "\tAND srr.resource_id = sre.id")
    List<SysResource> selectByUid(Long uid);
}
